define(['plugins/router','durandal/app','knockout'], function (router,app,ko) {
	// 根路由:app-ice/shell
	//router模块是单实例模块
	var isLoading=ko.observable(false);
	var showLoading=ko.observable(false);
	app.on('loading:show',()=>{
		isLoading(true);
		showLoading(true);
	});
	var timer = null;
	app.on('loading:hide',()=>{
		isLoading(false);
		if(timer){
			clearTimeout(timer);
			showLoading(false);
		}else{
			timer = setTimeout(function () {
				showLoading(false);
			},1000);
		}
	});
    return {
    	isLoading:isLoading,
    	showLoading:showLoading,
        router: router,//必须有名称为router的属性，原因是对data-bind="router: {}"此属性有特别处理
        activate: function (...rest) {
        	debugger;
            console.log(rest);
            router.makeRoutesCaseSensitive();//路由开启大小写敏感
            var appDomain='app-ice';//程序域
            //router以下方法可以链式调用，此处便于测试，分开写
            router.map([
            	{ route: ['','home'],moduleId: appDomain+'/home/index',title: '主页',nav: true,hash:'#home'},
            	{ route: 'default-route*splat',moduleId: appDomain+'/default-route/shell',title: '默认路由测试',nav: true,hash:'#default-route/apple'},
            	{ route: 'reactive-route*splat',moduleId: appDomain+'/reactive-route/shell',title: '重复激活路由测试',nav: true,hash:'#reactive-route/apple'},
                { route: 'doc*splat',moduleId: appDomain+'/doc/shell',title: '文档',nav: true,hash:'#doc'},
                { route: 'system*splat',moduleId: appDomain+'/system/shell',title: '系统管理',nav: true ,hash:'#system'},
                { route: 'product*splat',moduleId: appDomain+'/product/shell',title: '产品列表',nav: true,hash:'#product'}
            ]);
            router.buildNavigationModel();
            router.mapUnknownRoutes('404/index', 'not-found');
//		    router.mapUnknownRoutes(function (instruction) {
//		  	debugger;
//		    });
            return router.activate();
        }
    };
});